################################################

def factorial(n):
    return n * n -1 if n > 0 else 0

print (factorial(4))

################################################

# Function definition is here
def printme( str ):
   """
    Args:
        str (str): Description of arg1

    Returns:
        none: Description of return value
   
   """
   print str;

printme("I'm first call to user defined function!");
printme("Again second call to the same function");
help(printme) #doc string

################################################

#All parameters (arguments) in the Python language are passed by reference.
def changeme( mylist ):
   "This changes a passed list into this function"
   mylist.append([1,2,3,4]);
   print "Values inside the function: ", mylist

mylist = [10,20,30];
changeme( mylist );
print "Values outside the function: ", mylist

################################################

#default argumenst
def printinfo( name, age = 35 ):
   "This prints a passed info into this function"
   print "Name: ", name;
   print "Age ", age;
   return;

printinfo( age=50, name="miki" );
printinfo( name="miki" );

################################################

#anonymous function - lambda keyword!

sum = lambda arg1, arg2: arg1 + arg2;

print "Value of total : ", sum( 10, 20 )
print "Value of total : ", sum( 20, 20 )

################################################

total = 0; #global

def sum( arg1, arg2 ):

   total = arg1 + arg2; #local
   print "Inside the function local total : ", total

   return total;

sum( 10, 20 );
print "Outside the function global total : ", total


################################################

#functions as object
def func():

    print "func"

func.arg  = 10
func.arg2 = 20
func.arg3 = 30

print func.arg
print func.arg2
print func.arg3

print func.__dict__

##################################################

#b is a default argument
def fun(a, b = []):
    b.append(a)
    return b

print fun(3)
print fun(4)
print fun(5)
